<?php
/**
 * Created by PhpStorm.
 * User: wangchaozhen
 * Date: 2018/5/6
 * Time: 13:07
 */
namespace App\Common;

/**
 * Class Str
 * @package App\Common
 * 处理字符串的共有函数
 */
class Str
{
    /**
     * 获得随机字符串
     */
    public static function randString($length = 6,$type,$addchars = '')
    {
        switch ($type){
            case 1:
                //生成数字
                $chars = "0123456789".$addchars;
                break;
            case 2:
                //生成字符串随机
                $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".$addchars;
                break;
            default:
                $chars = "0123456789";
                break;
        }

        $chars = str_shuffle($chars);
        $str = substr($chars,0,$length);

        return $str;
    }
}